﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ElevatorLib
{
    /// <summary>
    /// Weibull分布
    /// </summary>
    public class WeibullDistr : ElevatorLib.IDistribution
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="rnd">随机数</param>
        /// <param name="alpha"></param>
        /// <param name="beta"></param>
        public WeibullDistr(Random rnd, double alpha, double beta)
        {
            if(alpha <= 0 || beta <= 0.0)
            {
                alpha = 0;
                beta = 0;
                throw new Exception("Alpha and beta must be greater than 0.0");
            }
            this.rnd = rnd;
            this.alpha = alpha;
            this.beta = beta;
        }

        #region Properties
        /// <summary>
        /// 随机数
        /// </summary>
        private Random rnd;
        /// <summary>
        /// 大于0
        /// </summary>
        private double alpha;
        /// <summary>
        /// 大于0
        /// </summary>
        private double beta;
        #endregion

        #region IDistribution 成员
        /// <summary>
        /// 生成样本
        /// </summary>
        /// <returns></returns>
        public double Sample()
        {
            return beta * Math.Pow(-Math.Log(Math.E,rnd.NextDouble()), (1 / alpha));
        }

        #endregion
    }
}
